#include <REGX52.H>
#include <INTRINS.H>

unsigned char a[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};


void Delay1ms(unsigned int xms)	//@12.000MHz
{
    unsigned char data i, j;
    while(xms)
    {
        i = 2;
        j = 239;
        do
            
        {
            while (--j);
        } while (--i);
        xms--;
    }
}
void main()
{
    int i=0,m=0,n=0;
    while (1)
    {
         if (P3_1==0)
         {
            Delay1ms(20);
            while (P3_1==0);
            Delay1ms(20);
             for (i=m;i<8;i++)
            {
                P2=a[i];
                Delay1ms(100);
                if (P3_0==0)
                {
                    Delay1ms(20);
                    while (P3_0==0);
                    Delay1ms(20);
                    m=i;
                    break;
                }
                if (i==7)
                {i=-1;m=-1;}
                
            }
         }
         else
         {
            if (P3_2==0)
            {
                Delay1ms(20);
                while (P3_2==0);
                Delay1ms(20);
                for (i=m;i<8;i--)
                {
                    P2=a[i];
                    Delay1ms(100);
                    if (P3_0==0)
                    {
                        Delay1ms(20);
                        while (P3_0==0);
                        Delay1ms(20);
                        m=i;
                        break;
                    }
                    if (i==0)
                    {i=8;m=8;}
                    
                }
            }
         }
    }
}
